package com.ddfeiyu.server.handler;

import com.ddfeiyu.agreement.ReconnectRequest;
import com.ddfeiyu.common.SocketChannelUtil;
import com.ddfeiyu.server.MyBizHandler;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReconnectHandler extends MyBizHandler<ReconnectRequest> {

    protected Logger logger = LoggerFactory.getLogger(ReconnectHandler.class);

    @Override
    public void channelRead(Channel channel, ReconnectRequest msg) {
        try {
            logger.info("NettyServer-ReconnectHandler客户端断线重连处理。traceId：{}", msg.getTraceId());
            SocketChannelUtil.removeUserChannelByUserId(msg.getTraceId());
            SocketChannelUtil.addChannel(msg.getTraceId(), channel);

        }catch (Exception e){
            logger.info("NettyServer-ReconnectHandler客户端断线重连处理异常。traceId：{}", msg.getTraceId(), e);
        }
    }
}
